<template>
  <div>
    <div v-if="!config.disabled">
      <el-radio-group
        :disabled="config.disabled"
        v-model="obj.type"
        @input="onRadioChange"
      >
        <el-radio label="1">中信码</el-radio>
        <el-radio label="2">机构信用码</el-radio>
      </el-radio-group>

      <el-input
        v-if="obj.type"
        :disabled="config.disabled"
        type="text"
        @input="onInputChange"
        v-model="obj.code"
        :placeholder="`请填写${obj.type * 1 === 1 ? '中信码' : '机构信用码'}`"
      />
    </div>
    <div v-else>
      <span v-if="obj.type * 1 === 1">中信码</span>
      <span v-else-if="obj.type * 1 === 2">机构信用码</span>
      <span class="ml-lg">{{ obj.code }}</span>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    value: {
      type: Object,
      default: () => {},
    },
    config: {
      type: Object,
      default: {},
    },
  },
  model: {
    prop: "value",
    event: "change",
  },
  data() {
    return {};
  },
  computed: {
    obj: {
      get() {
        return this.value || {};
      },
      set(val) {
        this.$emit("change", val);
      },
    },
  },
  methods: {
    onRadioChange(item) {
      this.obj = {
        type: item,
        code: "",
      };
    },
    onInputChange(item) {
      this.obj = {
        ...this.obj,
        code: item,
      };
    },
  },
};
</script>